package laba_1_1;


import java.util.Scanner;
import java.util.regex.Pattern;

class MFunctional {
	private int[] convFrStToArr(String val) {
		int[] array = new int[val.length()];
		for(int i = 0; i < val.length(); i++) {
			if(val.charAt(i) == 'A') {
				array[i] = 10;
			}
			else if(val.charAt(i) == 'B') {
				array[i] = 11;
			}
			else if(val.charAt(i) == 'C') {
				array[i] = 12;
			}
			else if(val.charAt(i) == 'D') {
				array[i] = 13;
			}
			else if(val.charAt(i) == 'E') {
				array[i] = 14;
			}
			else {
				array[i] = Character.digit(val.charAt(i), 10);
			}
		}
		return array;
	}
	
	public String binToOct(String val) {
		return String.valueOf(Integer.toOctalString(Integer.parseInt(val,2)));
	}

	public String fifteenTo9(String val) {
		int fPartOfFraction, fSum = 0;
		double sSum = 0;
		String fPart, sPart, finalSPart = "";
		Pattern p = Pattern.compile("[.,]+");
		Scanner s = new Scanner(val).useDelimiter(p);
		fPart = s.next();
		sPart = s.next();
		int[] fArray = convFrStToArr(fPart);
		int[] sArray = convFrStToArr(sPart);
		for(int i = 0; i < fArray.length; i++) {
			fSum += fArray[i]*Math.pow(15, fArray.length - (i+1));
		}
		for(int i = 0; i < sArray.length; i++) {
			sSum += sArray[i]*Math.pow(15, (-1-i));
		}
        for(int i=0;i<4;i++)
        {
            sSum = sSum * 9;
            fPartOfFraction = (int)(sSum);
            finalSPart += fPartOfFraction;
            sSum = sSum - fPartOfFraction;
        }
    	return(String.valueOf(Integer.toString(fSum, 9) + "." + finalSPart));
	}
}